home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / WLIST.ARJ / MISC.H < prev   
Text File  |  1992-05-15  |  5KB  |  159 lines

  1. #ifndef MiscIncluded
  2. #define MiscIncluded
  3.  
  4. // one big header file for miscelaneous odds n ends
  5. // this file is generally included by all other header files
  6.  
  7. typedef          char  Char;
  8. typedef unsigned char  Bool;
  9. typedef unsigned char  Byte;
  10. typedef signed   char  SByte;
  11. typedef unsigned short Word;
  12. typedef signed   short SWord;
  13. typedef unsigned int   Int;  // avoid using this:  provided for overloaded libarary consistancy
  14. typedef signed   int   SInt; // avoid using this:  provided for overloaded libarary consistancy
  15. typedef unsigned long  Long;
  16. typedef signed   long  SLong;
  17. typedef float          Float;   // for consistancy
  18. typedef double         Double;
  19.  
  20. typedef Byte* BytePointer;  // I use it in a few places...
  21.  
  22. // constants related to above types.  The Size of these things will stay the
  23. // same from system to system.
  24.  
  25. const Char  MaxChar  = 255;
  26. const Byte  MaxByte  = 255;
  27. const SByte MaxSByte = 127;
  28. const SByte MinSByte = (-128);
  29. const Word  MaxWord  = 0xFFFF;
  30. const SWord MaxSWord = 32767;
  31. const SWord MinSWord = 0x8000; // (-32768);
  32. const SLong MaxSLong = 0x7FFFFFFFL; // 2147483647;
  33. const Long  MaxLong  = 0xFFFFFFFFL;
  34. const SLong MinSLong = 0x80000000L; // (-2147483648);
  35.  
  36. const Bool True  = 1;
  37. const Bool False = 0;
  38. const Bool Yes   = 1;
  39. const Bool No    = 0;
  40. const Bool On    = 1;
  41. const Bool Off   = 0;
  42.  
  43. /* the following have values < 0 so that they may be used as alternatives to
  44.    text placement rountines that need positive values */
  45.  
  46. const SWord Left=(MinSWord+1);
  47. const SWord Center=(MinSWord+2);
  48. const SWord Right=(MinSWord+3);
  49.  
  50. const Word NotFound=MaxWord;
  51. const Long VecObjNotFound=MaxLong;
  52.   // used with some search functions.
  53.  
  54. /* misc. macros */
  55.  
  56. SByte  Abs(SByte  x);
  57. SWord  Abs(SWord  x);
  58. SInt   Abs(SInt  x);
  59. SLong  Abs(SLong  x);
  60. Float  Abs(Float  x);
  61. Double Abs(Double x);
  62.  
  63. Byte   Max(Byte   a, Byte b  );
  64. SByte  Max(SByte  a, SByte b );
  65. Word   Max(Word   a, Word b  );
  66. SWord  Max(SWord  a, SWord b );
  67. Int    Max(Int    a, Int b   );
  68. SInt   Max(SInt   a, SInt b  );
  69. Long   Max(Long   a, Long b  );
  70. SLong  Max(SLong  a, SLong b );
  71. double Max(double a, double b);
  72.  
  73. Byte   Min(Byte   a, Byte b  );
  74. SByte  Min(SByte  a, SByte b );
  75. Word   Min(Word   a, Word b  );
  76. SWord  Min(SWord  a, SWord b );
  77. Int    Min(Int    a, Int b   );
  78. SInt   Min(SInt   a, SInt b  );
  79. Long   Min(Long   a, Long b  );
  80. SLong  Min(SLong  a, SLong b );
  81. double Min(double a, double b);
  82.  
  83. Bool InRange(Byte   Val, Byte   Low, Byte   High);
  84. Bool InRange(SByte  Val, SByte  Low, SByte  High);
  85. Bool InRange(Word   Val, Word   Low, Word   High);
  86. Bool InRange(SWord  Val, SWord  Low, SWord  High);
  87. Bool InRange(Int    Val, Int    Low, Int    High);
  88. Bool InRange(SInt   Val, SInt   Low, SInt   High);
  89. Bool InRange(Long   Val, Long   Low, Long   High);
  90. Bool InRange(SLong  Val, SLong  Low, SLong  High);
  91. Bool InRange(double Val, double Low, double High);
  92. Bool InRange(long double Val, long double Low, long double High);
  93.  
  94. SLong Round(double Val);      //  .2 => 0    .7 => 1    -.2 => 0    -.7 => -1
  95. SLong RoundUp(double Val);    //  .2 => 1    .7 => 1    -.2 => 0    -.7 => 0
  96. SLong RoundDown(double Val);  //  .2 => 0    .7 => 0    -.2 => -1   -.7 => -1
  97. SLong RoundOut(double Val);   //  .2 => 1    .7 => 1    -.2 => -1   -.7 => -1
  98. SLong RoundIn(double Val);     //  .2 => 0    .7 => 0    -.2 => 0    -.7 => 0
  99.  
  100. Char ToUpper(Char C);
  101. Char ToLower(Char C);
  102.  
  103. void PigeonHole(Long TotQuan, Word ArrayLen, Word A[]);
  104.   // spreads TotQuan as evenly as possible over A
  105.  
  106. Long SystemTick(); // returns the current system tick
  107.  
  108. #include <dos.h>
  109. inline void Delay(Word MilliSecs) {delay(MilliSecs);}
  110.  
  111. void Sound(float Pitch,Word MilliSecs);
  112.   // a little bit of control over the pc speaker
  113.  
  114. void Beep(Byte Num=1);
  115.   // Num is the number of beeps ya want
  116.  
  117. #define Randomize() srand((int) time(NULL))
  118.   // Initializes (seeds) the random number generator
  119.  
  120. #define Random(Max) (Word(rand() % Max))
  121.   // returns a random integer in the range of 0 to Max excluding Max
  122.  
  123. #define DebugPause(Msg)  {puts(Msg "\n"); Delay(2500); }
  124.   // prints the message and then pauses a bit.  Used in debugging
  125.  
  126. #define CopyArray(Dest,Source) memcpy(Dest,Source,sizeof(Dest))
  127.   // Dest must be something that sizeof will work on
  128.  
  129. #define CopyString(Dest,Source) (strncpy(Dest,Source,sizeof(Dest)-1),Dest[sizeof(Dest)-1]=0)
  130.   // For the type (Char*,Char*) Dest must be something that sizeof will work on
  131.  
  132. #define ClearStruct(A) memset((void*)(&A),0,sizeof(A))
  133.   // fill a struct with zeros
  134.  
  135. #define ClearArray(A) memset(A,0,sizeof(A))
  136.   /* fill an array with zeros.  Array must be defined so that sizeof will
  137.      work on it */
  138.  
  139. // Given these objects, standard CRC16 will be calculated
  140. Word CRC(void* P,Long Size);
  141. Word CRC(const Char* S);
  142.  
  143. #define Loop while(1)
  144.   // structure for an infinite loop
  145.  
  146. #define For(TheVar,TheEnd)  for(TheVar=0;TheVar<TheEnd;TheVar++)
  147.   // Makes for a simpler, more readable, less error prone loop.
  148.   // Use  "For(I,10)" instead of "for(I=0;I<10;I++)"
  149.  
  150. typedef void (* VanillaFunctionPtr)(void);
  151. typedef void (* VoidFuncPtr)(void);
  152. typedef Bool (* BoolFuncPtr)(void);
  153.  
  154. void FatalError(const Char*);
  155.  
  156.  
  157. #endif
  158.  
  159.